home *** CD-ROM | disk | FTP | other *** search
/ Dr. Windows 3 / dr win3.zip / dr win3 / WINPROGS / WINSRC20.ZIP / FRACSUBR.C < prev    next >
Text File  |  1990-09-10  |  32KB  |  984 lines

  1. /*
  2. FRACSUBR.C contains subroutines which belong primarily to CALCFRAC.C and
  3. FRACTALS.C, i.e. which are non-fractal-specific fractal engine subroutines.
  4. */
  5.  
  6. #include <stdio.h>
  7. #include <stdarg.h>
  8. #include <float.h>
  9. #include "fractint.h"
  10. #include "fractype.h"
  11. #include "mpmath.h"
  12.  
  13. /* routines in this module    */
  14.  
  15. void calcfracinit(void);
  16. void adjust_corner(void);
  17. int  alloc_resume(int,int);
  18. int  put_resume(int,...);
  19. int  start_resume(void);
  20. int  get_resume(int,...);
  21. void end_resume(void);
  22. void iplot_orbit(long,long,int);
  23. void plot_orbit(double,double,int);
  24. void scrub_orbit(void);
  25. int  add_worklist(int,int,int,int,int,int,int);
  26. void tidy_worklist(void);
  27. int  ssg_blocksize(void);
  28. void symPIplot(int,int,int);
  29. void symPIplot2J(int,int,int);
  30. void symPIplot4J(int,int,int);
  31. void symplot2(int,int,int);
  32. void symplot2Y(int,int,int);
  33. void symplot2J(int,int,int);
  34. void symplot4(int,int,int);
  35. void symplot2basin(int,int,int);
  36. void symplot4basin(int,int,int);
  37. void get_julia_attractor(double,double);
  38.  
  39. static void adjust_to_limits(double);
  40. static void smallest_add(double *);
  41. static int  ratio_bad(double,double);
  42. static void plotdorbit(double,double,int);
  43. static int  combine_worklist(void);
  44.  
  45.  
  46. extern int    calc_status;        /* status of calculations */
  47. extern char far *resume_info;        /* pointer to resume info if allocated */
  48.        int    resume_len;        /* length of resume info */
  49. static int    resume_offset;        /* offset in resume info gets */
  50. extern double plotmx1,plotmx2,plotmy1,plotmy2; /* real->screen conversion */
  51. extern int    orbit_ptr;        /* pointer into save_orbit array */
  52. extern int far *save_orbit;        /* array to save orbit values */
  53. extern int    orbit_color;        /* XOR color */
  54. extern int    num_worklist;        /* resume worklist for standard engine */
  55. extern int    fractype;         /* fractal type */
  56. extern char   stdcalcmode;        /* '1', '2', 'g', 'b'       */
  57. extern char   floatflag;        /* floating-point fractals? */
  58. extern int    integerfractal;        /* TRUE if fractal uses integer math */
  59. extern struct workliststuff worklist[MAXCALCWORK];
  60. extern int    sxdots,sydots;        /* # of dots on the physical screen    */
  61. extern int    sxoffs,syoffs;        /* physical top left of logical screen */
  62. extern int    xdots, ydots;        /* # of dots on the logical screen     */
  63. extern int    colors;            /* maximum colors available */
  64. extern long   fudge;            /* fudge factor (2**n) */
  65. extern int    bitshift;         /* bit shift for fudge */
  66. extern double xxmin,xxmax,yymin,yymax,xx3rd,yy3rd; /* corners */
  67. extern long   xmin, xmax, ymin, ymax, x3rd, y3rd;  /* integer equivs */
  68. extern int    maxit;            /* try this many iterations */
  69. extern int    attractors;        /* number of finite attractors    */
  70. extern struct complex  attr[];        /* finite attractor vals (f.p)    */
  71. extern struct lcomplex lattr[];     /* finite attractor vals (int)    */
  72. extern struct complex  old,new;
  73. extern struct lcomplex lold,lnew;
  74. extern double tempsqrx,tempsqry;
  75. extern long   ltempsqrx,ltempsqry;
  76. extern int    xxstart,xxstop;        /* these are same as worklist, */
  77. extern int    yystart,yystop,yybegin;    /* declared as separate items  */
  78. extern int    periodicitycheck;
  79. extern int    basin;
  80. extern int    finattract;
  81. extern int    pixelpi;            /* value of pi in pixels */
  82. extern double closenuff;
  83. extern long   lclosenuff;
  84. extern int    ixstart, ixstop, iystart, iystop;
  85. extern int    color;
  86. extern int    decomp[];
  87. extern double potparam[3];        /* three potential parameters*/
  88. extern int    distest;            /* non-zero if distance estimator */
  89. extern double param[4];         /* up to four parameters */
  90. extern int    invert;            /* non-zero if inversion active */
  91. extern int    biomorph;
  92. extern int    debugflag; /* internal use only - you didn't see this */
  93. extern long   creal, cimag;        /* for calcmand */
  94. extern long   delx, dely;        /* screen pixel increments  */
  95. extern long   delx2, dely2;        /* screen pixel increments  */
  96. extern double delxx, delyy;        /* screen pixel increments  */
  97. extern double delxx2, delyy2;        /* screen pixel increments  */
  98. extern long   delmin;            /* for calcfrac/calcmand    */
  99. extern double ddelmin;            /* same as a double        */
  100. extern int    potflag;            /* continuous potential flag */
  101. extern int    bailout;
  102. extern double rqlim;
  103. extern double  dxsize, dysize;        /* xdots-1, ydots-1        */
  104.  
  105. extern long   far *lx0, far *ly0;    /* x, y grid            */
  106. extern long   far *lx1, far *ly1;    /* adjustment for rotate    */
  107. /* note that lx1 & ly1 values can overflow into sign bit; since     */
  108. /* they're used only to add to lx0/ly0, 2s comp straightens it out  */
  109. extern double far *dx0, far *dy0;    /* floating pt equivs */
  110. extern double far *dx1, far *dy1;
  111.  
  112. extern char   usr_floatflag;
  113. extern char   usr_stdcalcmode;
  114. extern int    usr_periodicitycheck;
  115. extern int    usr_distest;
  116.  
  117. extern int StandardFractal(void);
  118. extern int calcmand(void);
  119.  
  120. #define FUDGEFACTOR    29    /* fudge all values up by 2**this */
  121. #define FUDGEFACTOR2    24    /* (or maybe this)          */
  122.  
  123.  
  124. void calcfracinit() /* initialize a *pile* of stuff for fractal calculation */
  125. {
  126.    int i;
  127.    double ftemp;
  128.  
  129. init_restart:
  130.  
  131.    /* the following variables may be forced to a different setting due to
  132.       calc routine constraints;  usr_xxx is what the user last said is wanted,
  133.       xxx is what we actually do in the current situation */
  134.    stdcalcmode        = usr_stdcalcmode;
  135.    periodicitycheck = usr_periodicitycheck;
  136.    distest        = usr_distest;
  137.    floatflag        = usr_floatflag;
  138.  
  139.    if (distest) /* force floating point for dist est */
  140.       floatflag = 1;
  141.  
  142.    potflag = 0;
  143.    if (potparam[0] != 0.0
  144.      && colors >= 256
  145.      && (fractalspecific[fractype].calctype == StandardFractal
  146.      || fractalspecific[fractype].calctype == calcmand))
  147.       potflag = 1;
  148.  
  149.    if (floatflag) { /* ensure type matches floatflag */
  150.       if (fractalspecific[fractype].isinteger != 0
  151.     && fractalspecific[fractype].tofloat != NOFRACTAL)
  152.      fractype = fractalspecific[fractype].tofloat;
  153.       }
  154.    else {
  155.       if (fractalspecific[fractype].isinteger == 0
  156.     && fractalspecific[fractype].tofloat != NOFRACTAL)
  157.      fractype = fractalspecific[fractype].tofloat;
  158.       }
  159.  
  160.    integerfractal = fractalspecific[fractype].isinteger;
  161.  
  162.    if (potflag && potparam[2] != 0.0)
  163.       rqlim = potparam[2];
  164.    else if (decomp[0] > 0 && decomp[1] > 0)
  165.       rqlim = (double)decomp[1];
  166.    else if (bailout) /* user input bailout */
  167.       rqlim = bailout;
  168.    else if (biomorph != -1) /* biomorph benefits from larger bailout */
  169.       rqlim = 100;
  170.    else if (distest) {
  171.       rqlim = 100000.0;
  172.       if (fractype == FPMANZTOZPLUSZPWR || fractype == FPJULZTOZPLUSZPWR)
  173.      rqlim = 100; /* reduce it to avoid fp math overflow */
  174.       }
  175.    else
  176.       rqlim = fractalspecific[fractype].orbit_bailout;
  177.    if (integerfractal) /* the bailout limit mustn't be too high here */
  178.       if (rqlim > 127.0) rqlim = 127.0;
  179.  
  180.    if (fractalspecific[fractype].flags&NOROTATE != 0) {
  181.       /* ensure min<max and unrotated rectangle */
  182.       if (xxmin > xxmax) { ftemp = xxmax; xxmax = xxmin; xxmin = ftemp; }
  183.       if (yymin > yymax) { ftemp = yymax; yymax = yymin; yymin = ftemp; }
  184.       xx3rd = xxmin; yy3rd = yymin;
  185.       }
  186.  
  187.    /* set up bitshift for integer math */
  188.    bitshift = FUDGEFACTOR2; /* by default, the smaller shift */
  189.    if (integerfractal > 1)  /* use specific override from table */
  190.       bitshift = integerfractal;
  191.    if (integerfractal == 0) /* float? */
  192.       if ((i = fractalspecific[fractype].tofloat) != NOFRACTAL) /* -> int? */
  193.      if (fractalspecific[i].isinteger > 1) /* specific shift? */
  194.         bitshift = fractalspecific[i].isinteger;
  195.  
  196.    if (fractype == MANDEL || fractype == JULIA) { /* adust shift bits if.. */
  197.       if (potflag == 0                  /* not using potential */
  198.     && (fractype != MANDEL              /* and not an int mandel */
  199.         || (param[0] == 0.0 && param[1] == 0.0))  /* w/ "fudged" params */
  200.     && !invert                  /* and not inverting */
  201.     && biomorph == -1              /* and not biomorphing */
  202.     && rqlim <= 4.0               /* and bailout not too high */
  203.     && debugflag != 1234)              /* and not debugging */
  204.      bitshift = FUDGEFACTOR;          /* use the larger bitshi